package com.jk.smartelderlycare.controller;

import com.jk.smartelderlycare.dto.SysDynamics;
import com.jk.smartelderlycare.pojo.PagedResponse;
import com.jk.smartelderlycare.pojo.ResponseResult;
import com.jk.smartelderlycare.service.SysDynamicsServiceFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author hhk
 * @version 1.0
 * @ClassName SysDynamicsController
 * @program: smart-elderly-care
 * @description: TODO
 * @date 2024/11/19 20:37
 */
@Api(tags = "动态管理")
@Slf4j
@RestController
@RequestMapping(value = "dynamics")
public class SysDynamicsController {
    @Autowired
    private SysDynamicsServiceFeign sysDynamicsServiceFeign;


    /**
     * @description: 动态列表后端分页查询
     * @param: [sysDynamics, pageNum, pageSize]
     * @return: com.jk.smartelderlycare.pojo.ResponseResult<com.jk.smartelderlycare.pojo.PagedResponse<com.jk.smartelderlycare.dto.SysDynamics>>
     * @author hhk
     * @date: 2024/11/19 20:44
     */
    @ApiOperation(value = "动态列表后端分页查询",httpMethod = "POST",notes = "动态列表后端分页查询")
    @PostMapping(value = "findSysDynamicsPaginationList")
    public ResponseResult<PagedResponse<SysDynamics>> findSysDynamicsPaginationList(@RequestBody SysDynamics sysDynamics, @RequestParam(value = "pageNum") Integer pageNum, @RequestParam(value = "pageSize") Integer pageSize){
        return new ResponseResult<>(200,"查询成功",sysDynamicsServiceFeign.findSysDynamicsPaginationList(sysDynamics,pageNum,pageSize));
    }
    /**
     * @description: 根据id查询一条动态
     * @param: [dynamicsId]
     * @return: com.jk.smartelderlycare.pojo.ResponseResult<com.jk.smartelderlycare.dto.SysDynamics>
     * @author hhk
     * @date: 2024/11/19 20:43
     */
    @ApiOperation(value = "根据id查询一条动态",httpMethod = "GET",notes = "根据id查询一条动态")
    @GetMapping(value = "findSysDynamicsById")
    public ResponseResult<SysDynamics> findSysDynamicsById(@RequestParam(value = "dynamicsId") Long dynamicsId){
            return new ResponseResult<>(200,"查询成功",sysDynamicsServiceFeign.findSysDynamicsById(dynamicsId));
    }
    /**
     * @description: 删除一条动态
     * @param: [dynamicsId]
     * @return: com.jk.smartelderlycare.pojo.ResponseResult
     * @author hhk
     * @date: 2024/11/19 20:42
     */
    @ApiOperation(value = "删除一条动态",httpMethod = "DELETE",notes = "删除一条动态")
    @DeleteMapping(value = "deleteSysDynamicsById")
    public ResponseResult deleteSysDynamicsById(@RequestParam(value = "dynamicsId") Long dynamicsId){
        try {
            sysDynamicsServiceFeign.deleteSysDynamicsById(dynamicsId);
            return new ResponseResult(200,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(500,"删除失败");
        }
    }
    /**
     * @description: 添加动态
     * @param: [sysDynamics]
     * @return: com.jk.smartelderlycare.pojo.ResponseResult
     * @author hhk
     * @date: 2024/11/19 20:41
     */
    @ApiOperation(value = "添加动态",httpMethod = "POST",notes = "添加动态")
    @PostMapping(value = "addSysDynamics")
    public ResponseResult addSysDynamics(@RequestBody SysDynamics sysDynamics){
        try {
            sysDynamicsServiceFeign.addSysDynamics(sysDynamics);
            return new ResponseResult(200,"添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(500,"添加失败");
        }
    }
    /**
     * @description: 修改动态
     * @param: [sysDynamics]
     * @return: com.jk.smartelderlycare.pojo.ResponseResult
     * @author hhk
     * @date: 2024/11/19 20:46
     */
    @ApiOperation(value = "修改动态",httpMethod = "PUT",notes = "修改动态")
    @PutMapping(value = "updateSysDynamics")
    public ResponseResult updateSysDynamics(@RequestBody SysDynamics sysDynamics){
        try {
            sysDynamicsServiceFeign.updateSysDynamics(sysDynamics);
            return new ResponseResult(200,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(500,"修改失败");
        }
    }




    /**
     * @description: 修改状态
     * @param: [sysDynamics]
     * @return: com.jk.smartelderlycare.pojo.ResponseResult
     * @author hhk
     * @date: 2024/11/19 20:46
     */
    @ApiOperation(value = "修改状态",httpMethod = "PUT",notes = "修改状态")
    @PutMapping(value = "updateStatusById")
    public ResponseResult updateStatusById(@RequestBody SysDynamics sysDynamics){
        try {
            sysDynamicsServiceFeign.updateStatusById(sysDynamics);
            return new ResponseResult(200,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(500,"修改失败");
        }
    }

    /**
     * @description: 批量删除动态
     * @param: [ids]
     * @return: com.jk.smartelderlycare.pojo.ResponseResult
     * @author hhk
     * @date: 2024/11/19 20:47
     */
    @ApiOperation(value = "批量删除动态",httpMethod = "DELETE",notes = "批量删除动态")
    @DeleteMapping(value = "deleteSysDynamicsByIds")
    public ResponseResult deleteSysDynamicsByIds(@RequestParam List<Long> ids){
        try {
            sysDynamicsServiceFeign.deleteSysDynamicsByIds(ids);
            return new ResponseResult(200,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(500,"删除失败");
        }
    }











}
